#include <stdio.h>
#include <winsock2.h>

#pragma comment(lib, "Ws2_32.lib")

int main()
{
    char sendBuf[256] = { 0 };
    char receiveBuf[256] = { 0 };

    int sendLength = 0;
    int receiveLength = 0;
    int length = 0;

    SOCKET socket_server;
    SOCKET socket_receive;

    SOCKADDR_IN server_addr;
    SOCKADDR_IN client_addr;

    WSADATA wsaData;
    WORD sockVersion = MAKEWORD(2, 2);
    if (WSAStartup(sockVersion, &wsaData) != 0)
    {
        printf("WSAStartup failed:%d\n", WSAGetLastError());
        return 0;
    }

    if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2)
    {
        printf("Version error!\n");
    }

    socket_server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (socket_server == INVALID_SOCKET)
    {
        printf("socket error:%d\n", WSAGetLastError());
        return 0;
    }

    server_addr.sin_addr.S_un.S_addr = htonl(INADDR_ANY);
    server_addr.sin_family = AF_INET;


    int ret = bind(socket_server, (SOCKADDR *)&server_addr, sizeof(SOCKADDR));
    if (ret != 0)
    {
        printf("bind error:%d\n", WSAGetLastError());
    }

    listen(socket_server, 20);

    length = sizeof(SOCKADDR);

    socket_receive = accept(socket_server, (SOCKADDR *)&client_addr, &length);

    while (1)
    {
        receiveLength = recv(socket_receive, receiveBuf, 256, 0);

    }

    return 0;
}
